﻿import { Component, Injector, ViewChild } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { AuditLogServiceProxy} from '@shared/service-proxies/service-proxies';
import { ModalDirective } from 'ngx-bootstrap';
import { finalize } from 'rxjs/operators';
import { Table } from 'primeng/components/table/table';
import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent';
import { Paginator } from 'primeng/components/paginator/paginator';
import * as moment from 'moment';
@Component({
    selector: 'logCodeBaseModal',
    templateUrl: './log-code-base-modal.component.html'
})
export class LogCodeBaseModalComponent extends AppComponentBase {

    @ViewChild('editModal') modal: ModalDirective;
    @ViewChild('dataTable') dataTable: Table;
    @ViewChild('paginator') paginator: Paginator;

    saving = false;
    resettingPermissions = false;

    userId: number;
    userName: string;

    constructor(
        injector: Injector,
        private _auditLogServiceProxy: AuditLogServiceProxy
    ) {
        super(injector);
    }

    show(standardPartsId?: string): void {
        this.modal.show();
    }

    save(): void {
        /*
        let input = new UpdateUserPermissionsInput();

        input.id = this.userId;


        this.saving = true;
        this._userService.updateUserPermissions(input)
            .pipe(finalize(() => { this.saving = false; }))
            .subscribe(() => {
                this.notify.info(this.l('SavedSuccessfully'));
                this.close();
            });*/
    }
    getLogs(event?: LazyLoadEvent) {

        /*
        this.primengTableHelper.showLoadingIndicator();
        this.primengTableHelper.totalRecordsCount = 1;
        this.primengTableHelper.records = [{code:'T001',name:'标准件1'}]
        this.primengTableHelper.hideLoadingIndicator();*/

        if (this.primengTableHelper.shouldResetPaging(event)) {
            this.paginator.changePage(0);
            return;
        }
        let startMoment = moment(new Date());
        startMoment.subtract(60,"days");
        let entMoment = moment(new Date());
       
         this._auditLogServiceProxy.getAuditLogs(
            startMoment,//startDate: moment.Moment | null | undefined, 
            entMoment,//endDate: moment.Moment | null | undefined, 
            "admin",//userName: string | null | undefined, 
            "StandardPartsDetailAppService",//serviceName: string | null | undefined, 
            undefined,//methodName: string | null | undefined, 
            undefined,//browserInfo: string | null | undefined, 
            undefined,//hasException: boolean | null | undefined, 
            undefined,//minExecutionDuration: number | null | undefined, 
            undefined,//maxExecutionDuration: number | null | undefined, 
            this.primengTableHelper.getSorting(this.dataTable),//sorting: string | null | undefined, 
            this.primengTableHelper.getMaxResultCount(this.paginator, event),//maxResultCount: number | null | undefined, 
            this.primengTableHelper.getSkipCount(this.paginator, event) //skipCount: number | null | undefined             
         ).pipe(finalize(() => this.primengTableHelper.hideLoadingIndicator())).subscribe(result => {
             this.primengTableHelper.totalRecordsCount = result.totalCount;
             this.primengTableHelper.records = result.items;
             this.primengTableHelper.hideLoadingIndicator();
         });
    }
    resetPermissions(): void {
/*
        let input = new EntityDtoOfInt64();

        input.id = this.userId;

        this.resettingPermissions = true;
        this._userService.resetUserSpecificPermissions(input).subscribe(() => {
            this.notify.info(this.l('ResetSuccessfully'));
            this._userService.getUserPermissionsForEdit(this.userId).subscribe(result => {

            });
        }, undefined, () => {
            this.resettingPermissions = false;
        });*/
    }

    close(): void {
        this.modal.hide();
    }
    getCodeBase($event:Object){
        return [];
    }
    
}
